function logOut() {
    $.ajax({
        type: 'post',
        url: '/admin/logOut',
        data: {},
        dataType: 'json',
        contentType: 'application/json',
        cache: false
    }).done(function (data) {
        if (data.successFlg) {
            localStorage.setItem("userInfo", '');
            window.location.href = "/admin/login";
        } else {
            alert(data.errMsg);
        }
    });
}

function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]);
    return null;
}

Array.prototype.remove = function (val) {
    var index = this.indexOf(val);
    if (index > -1) {
        this.splice(index, 1);
    }
};

/**
 * 压缩图片
 * @param file input获取到的文件
 * @param callback 回调函数，压缩完要做的事，例如ajax请求等。
 */
function compressFile(file, callback) {
    var fileObj = file;
    var reader = new FileReader()
    reader.readAsDataURL(fileObj) //转base64
    reader.onload = function (e) {
        var image = new Image() //新建一个img标签（还没嵌入DOM节点)
        image.src = e.target.result
        image.onload = function () {
            var canvas = document.createElement('canvas'), // 新建canvas
                context = canvas.getContext('2d'),
                imageWidth = image.width / 2,    //压缩后图片的大小
                imageHeight = image.height / 2,
                data = ''
            canvas.width = imageWidth
            canvas.height = imageHeight
            context.drawImage(image, 0, 0, imageWidth, imageHeight)
            data = canvas.toDataURL('image/jpeg') // 输出压缩后的base64
            var arr = data.split(','), mime = arr[0].match(/:(.*?);/)[1], // 转成blob
                bstr = atob(arr[1]), n = bstr.length, u8arr = new Uint8Array(n);
            while (n--) {
                u8arr[n] = bstr.charCodeAt(n);
            }
            var files = new window.File([new Blob([u8arr], {type: mime})], 'test.jpeg', {type: 'image/jpeg'}) // 转成file
            callback(files) // 回调
        }
    }
}

// 输入时间戳, 输出格式化的时间
function formatDate(timestamp) {
    var date = new Date(timestamp / 1);
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var day = date.getDate();
    return year + '-' + month + '-' + day;
}

function formatDateFull(timestamp) {
    var date = new Date(timestamp / 1);
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var day = date.getDate();
    var hour = date.getHours();
    var minute = date.getMinutes();
    var second = date.getSeconds();
    return year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
}

function formateExamType(input) {
    switch (input) {
        case 1:
            return '真题试卷';
        case 2:
            return '模拟考';
        case 3:
            return '智能组卷';
        case 4:
            return '随机套题';
        default:
            return '未知';
    }
}

function formateQuestionType(input){
    switch (input) {
        case 1:
            return '单选题';
        case 2:
            return '多选题';
        case 3:
            return '主观题';
        default:
            return '未知';
    }
}

function toLocalISODate(timestamp) {
    timestamp = timestamp / 1;
    const date = new Date(timestamp);
    const offset = date.getTimezoneOffset() * 60000; // 时区偏移量（毫秒）
    const localTime = new Date(timestamp - offset);
    return localTime.toISOString().slice(0, 16);
}